(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "mobile/services/shoppingService", "react", "mobile/site", "mobile/controls/tabs", "mobile/controls/dataList", "mobile/controls/button", "mobile/controls/imageBox"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const shoppingService_1 = require("mobile/services/shoppingService");
    const React = require("react");
    const site_1 = require("mobile/site");
    const tabs_1 = require("mobile/controls/tabs");
    const dataList_1 = require("mobile/controls/dataList");
    const button_1 = require("mobile/controls/button");
    const imageBox_1 = require("mobile/controls/imageBox");
    // let orderListView: OrderListView;
    // let shop = page.createService(ShoppingService);
    // let type = page.data.type;
    let defaultActiveIndex = 0;
    class OrderListView extends React.Component {
        constructor(props) {
            super(props);
            this.loadData = (pageIndex) => {
                let type;
                if (this.state.activeIndex == 1)
                    type = "WaitingForPayment";
                else if (this.state.activeIndex == 2)
                    type = 'Send';
                return this.shop.myOrderList(pageIndex, type);
            };
            this.state = { activeIndex: defaultActiveIndex };
            this.shop = this.props.createService(shoppingService_1.ShoppingService);
        }
        activeItem(index) {
            // this.state.activeIndex = index;
            // this.setState(this.state);
            this.setState({ activeIndex: index });
            // orderListView.state.activeIndex = index;
            // orderListView.setState(orderListView.state);
        }
        componentDidUpdate() {
            this.dataList.reset();
            this.dataList.loadData();
        }
        pay() {
            return Promise.resolve();
        }
        confirmReceived() {
            return Promise.resolve();
        }
        /** 评价晒单 */
        evaluate() {
        }
        statusControl(order) {
            let control;
            let btnClassName = 'btn btn-small btn-primary pull-right';
            switch (order.Status) {
                case 'WaitingForPayment':
                    control = React.createElement("a", { href: `#shopping/purchase?id=${order.Id}`, className: btnClassName }, "\u7ACB\u5373\u4ED8\u6B3E");
                    break;
                case 'Send':
                    control = React.createElement(button_1.Button, { className: btnClassName, onClick: () => this.confirmReceived(), confirm: '你确定收到货了吗？' }, "\u786E\u8BA4\u6536\u8D27");
                    break;
                case 'ToEvaluate':
                    control = React.createElement("a", { href: '#shopping_evaluation', className: btnClassName }, "\u8BC4\u4EF7\u6652\u5355");
                    break;
                case 'Canceled':
                    control = React.createElement("label", { className: "pull-right" }, "\u5DF2\u53D6\u6D88");
                    break;
                case 'Paid':
                    control = React.createElement("label", { className: "pull-right" }, "\u5DF2\u4ED8\u6B3E");
                    break;
                case 'Evaluated':
                    control = React.createElement("label", { className: "pull-right" }, "\u5DF2\u8BC4\u4EF7");
                    break;
                case 'Received':
                    control = React.createElement("label", { className: "pull-right" }, "\u5DF2\u6536\u8D27");
                    break;
                default:
                    return null;
            }
            return control;
        }
        render() {
            return React.createElement(React.Fragment, null,
                React.createElement("header", null,
                    site_1.defaultNavBar(this.props.source, { title: '我的订单', }),
                    "      ",
                    React.createElement(tabs_1.Tabs, { className: "tabs", defaultActiveIndex: defaultActiveIndex, onItemClick: (index) => this.activeItem(index), scroller: () => this.dataView },
                        React.createElement("span", null, "\u5168\u90E8"),
                        React.createElement("span", null, "\u5F85\u4ED8\u6B3E"),
                        React.createElement("span", null, "\u5F85\u6536\u8D27"))),
                React.createElement("section", { ref: o => this.dataView = o },
                    React.createElement(dataList_1.DataList, { ref: o => this.dataList = o, loadData: (pageIndex) => this.loadData(pageIndex), dataItem: (o) => (React.createElement("div", { key: o.Id, className: "order-item" },
                            React.createElement("hr", null),
                            React.createElement("div", { className: "header" },
                                React.createElement("a", { href: `#shopping_orderDetail?id=${o.Id}` },
                                    React.createElement("h4", null,
                                        "\u8BA2\u5355\u7F16\u53F7\uFF1A",
                                        o.Serial),
                                    React.createElement("div", { className: "pull-right" },
                                        React.createElement("i", { className: "icon-chevron-right" })))),
                            React.createElement("div", { className: "body" },
                                React.createElement("ul", null, o.OrderDetails.map((c, i) => (React.createElement("li", { key: i },
                                    React.createElement(imageBox_1.ImageBox, { src: c.ImageUrl, className: "img-responsive img-thumbnail img-full" }))))),
                                o.OrderDetails.length == 1 ?
                                    React.createElement("div", { className: "pull-right", style: { width: '75%', fontSize: '16px', paddingLeft: '16px', paddingTop: '4px' } }, o.OrderDetails[0].ProductName)
                                    : null,
                                React.createElement("div", { className: "clearfix" })),
                            React.createElement("div", { className: "footer" },
                                React.createElement("h4", { className: "pull-left" },
                                    "\u5B9E\u4ED8\u6B3E\uFF1A",
                                    React.createElement("span", { className: "price" },
                                        "\uFFE5",
                                        o.Amount.toFixed(2))),
                                React.createElement("div", { className: "pull-right" }, this.statusControl(o))))), emptyItem: React.createElement("div", { className: "norecords" },
                            React.createElement("div", { className: "icon" },
                                React.createElement("i", { className: "icon-list" })),
                            React.createElement("h4", { className: "text" }, "\u6682\u65E0\u6B64\u7C7B\u8BA2\u5355")) })));
        }
    }
    exports.default = OrderListView;
});
